#include <gtk/gtk.h>

//signal callback for button press
static void button_callback (GtkWidget *widget,
			     gpointer  data)
{
    g_print ("calling button call with data: %s\n", (gchar *) data);
}

//event callback for delete_event
static gboolean delete_event (GtkWidget *widget,
			      GdkEvent  *event,
			      gpointer  data)
{
    gtk_main_quit ();
    return FALSE;
}

int main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *table;
    GtkWidget *button;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title ( GTK_WINDOW (window), "Table Packing");

    g_signal_connect (G_OBJECT (window), "delete_event",
		      G_CALLBACK (delete_event), NULL);

    gtk_container_set_border_width (GTK_CONTAINER (window), 20);

    //create a new table size 2x2 with homogenous (same size) boxes
    table = gtk_table_new (2, 2, TRUE);

    gtk_container_add (GTK_CONTAINER (window), table);

    button = gtk_button_new_with_label ("Button 1");
    g_signal_connect (G_OBJECT (button), "clicked",
		      G_CALLBACK (button_callback), (gpointer) "Button Uno");

    //attach our button to the table. left, right, top, bottom
    gtk_table_attach_defaults ( GTK_TABLE (table), button, 0, 1, 0, 1);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Button 2");
    g_signal_connect (G_OBJECT (button), "clicked",
		      G_CALLBACK (button_callback), (gpointer) "Button Dos");
    gtk_table_attach_defaults ( GTK_TABLE (table), button, 1, 2, 0, 1);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Quit");
    g_signal_connect (G_OBJECT (button), "clicked",
		      G_CALLBACK (delete_event), NULL);
    gtk_table_attach_defaults ( GTK_TABLE (table), button, 0, 2, 1, 2);
    gtk_widget_show (button);

    gtk_widget_show (table);
    gtk_widget_show (window);

    gtk_main ();
    return 0;
}
